<template>
<div>
  <Table :columns="columns" :data="data">
    <template slot-scope="{ row, index }" slot="action">
      <Button type="primary" size="small" style="margin-right: 5px" @click="editzswgyManager(row)">编辑</Button>
<!--      <Button type="error" size="small" style="margin-right: 5px" @click="deletezswgyManager(row)">删除</Button>-->
<!--      <Button type="primary" size="small" style="margin-right: 5px" @click="addTimerManager()">添加</Button>-->
      <!-- <Button v-if="row.manager===undefined || row.manager===''" type="info" size="small" style="margin-right: 5px" @click="addZBPerson(row)">专班人员管理</Button> -->
    </template>
  </Table>
  <Modal
    v-model="timerModal"
    title="添加定时"
    @on-ok="disposeManage">
        <Form :label-width="150">
      <FormItem label="网格名称：">
        <Input v-model="addTimerParams.name" style="width: 300px" disabled/>
      </FormItem>
<!--      <FormItem label="网格坐标：">-->
<!--        <Input v-model="addTimerParams.name" style="width: 300px" />-->
<!--      </FormItem>-->
      <FormItem label="巡查次数：">
        <span>一日</span>
        <InputNumber size="small" :max="10" :min="0" style="margin: 0 5px" @on-change="numberChange" :value="parseInt(addTimerParams.count)"></InputNumber>
        <span>次</span>
      </FormItem>
    </Form>
  </Modal>
</div>
</template>

<script>
import lodash from 'lodash'
import {
  findTimeList,
  updateTimeList,
  insertTimeList
} from '@/api/eventlist'
export default {
  name: 'addTimerManger',
  props: {
    pickInfo: Object
  },
  data () {
    return {
      addTimerParams: {},
      data: [],
      columns: [
        {
          title: '名称',
          key: 'name'
        },
        {
          title: '巡查次数',
          key: 'count'
        },
        {
          title: '操作',
          slot: 'action'
        }
      ],
      timerModal: false,
      editStatus: false
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    editzswgyManager (row) {
      this.addTimerParams = lodash.cloneDeep(row)
      this.editStatus = true
      this.timerModal = true
    },
    // addTimerManager () {
    //   this.timerModal = true
    //   this.editStatus = false
    // },
    disposeManage () {
      if (this.editStatus) {
        updateTimeList({ id: this.addTimerParams.id, count: this.addTimerParams.count }).then(ret => {
          if (ret.data.errcode === 0) {
            this.init()
          } else {
            this.$Notice.error({
              title: '查询失败',
              desc: ret.data.errmsg
            })
          }
        })
      } else {
        debugger
        insertTimeList(data).then(ret => {
          if (ret.data.errcode === 0) {
            this.init()
          } else {
            this.$Notice.error({
              title: '查询失败',
              desc: ret.data.errmsg
            })
          }
        })
      }
    },
    numberChange (e) {
      console.log(e + '次数')
      this.addTimerParams.count = e
    },
    init () {
      let data = {
        id: this.pickInfo.id
      }
      findTimeList(data).then(ret => {
        if (ret.data.errcode === 0) {
          this.data = ret.data.data
        } else {
          this.$Notice.error({
            title: '查询失败',
            desc: ret.data.errmsg
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
